All files / app/(tabs)/beneficiaries/[id] equipment.tsx

0% Statements 0/134
0% Branches 0/74
0% Functions 0/32
0% Lines 0/124

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
import React, { useState, useEffect, useCallback } from 'react';
import {
  View,
  Text,
  StyleSheet,
  ScrollView,
  TouchableOpacity,
  Alert,
  ActivityIndicator,
  RefreshControl,
  Platform,
  ActionSheetIOS,
} from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import { router, useLocalSearchParams } from 'expo-router';
import * as Device from 'expo-device';
import { useBeneficiary } from '@/contexts/BeneficiaryContext';
import { useBLE } from '@/contexts/BLEContext';
import { api, ROOM_LOCATIONS } from '@/services/api';
import type { WPSensor } from '@/types';
import {
  AppColors,
  BorderRadius,
  FontSizes,
  FontWeights,
  Spacing,
  Shadows,
} from '@/constants/theme';
import { BeneficiaryMenu } from '@/components/ui/BeneficiaryMenu';
import { useDebounce } from '@/hooks/useDebounce';
 
const sensorConfig = {
  icon: 'water' as const,
  label: 'WP Sensor',
  color: AppColors.primary,
  bgColor: AppColors.primaryLighter,
};
 
export default function EquipmentScreen() {
  const { id } = useLocalSearchParams<{ id: string }>();
  const { currentBeneficiary } = useBeneficiary();
  const { isBLEAvailable } = useBLE();
 
  // State for API sensors (attached to beneficiary)
  const [apiSensors, setApiSensors] = useState<WPSensor[]>([]);
  const [isLoading, setIsLoading] = useState(true);
  const [isRefreshing, setIsRefreshing] = useState(false);
  const [isDetaching, setIsDetaching] = useState<string | null>(null);
  const [error, setError] = useState<string | null>(null);
 
  const beneficiaryName = currentBeneficiary?.name || 'this person';
 
  useEffect(() => {
    loadSensors();
  }, [id]);
 
  const loadSensors = async () => {
    if (!id) {
      return;
    }
 
    try {
      setIsLoading(true);
      setError(null);
 
      // Get WP sensors from API (attached to beneficiary)
      const response = await api.getDevicesForBeneficiary(id);
 
      if (!response.ok) {
        setError(response.error?.message || 'Failed to load sensors');
        setApiSensors([]);
        return;
      }
 
      setApiSensors(response.data || []);
    } catch (error) {
      setError(error instanceof Error ? error.message : 'Failed to load sensors');
      setApiSensors([]);
    } finally {
      setIsLoading(false);
      setIsRefreshing(false);
    }
  };
 
  const handleRefreshInternal = useCallback(() => {
    setIsRefreshing(true);
    loadSensors();
  }, [id]);
 
  const { debouncedFn: handleRefresh } = useDebounce(handleRefreshInternal, { delay: 1000 });
 
  // Handle sensor click - show action sheet for offline, navigate to settings for online
  const handleSensorPress = (sensor: WPSensor) => {
    // For offline API sensors - show reconnect options
    if (sensor.source === 'api' && sensor.status === 'offline') {
      if (Platform.OS === 'ios') {
        ActionSheetIOS.showActionSheetWithOptions(
          {
            title: `${sensor.name} is Offline`,
            message: `Last seen: ${formatLastSeen(sensor.lastSeen)}`,
            options: ['Cancel', 'Reconnect via Bluetooth', 'Remove from this home'],
            destructiveButtonIndex: 2,
            cancelButtonIndex: 0,
          },
          buttonIndex => {
            if (buttonIndex === 1) {
              // Reconnect - go to setup-wifi flow
              router.push(`/(tabs)/beneficiaries/${id}/setup-wifi?deviceId=${sensor.deviceId}&deviceName=${sensor.name}&wellId=${sensor.wellId}` as any);
            } else if (buttonIndex === 2) {
              // Remove
              handleDetachDevice(sensor);
            }
          }
        );
      } else {
        // Android fallback
        Alert.alert(
          `${sensor.name} is Offline`,
          `Last seen: ${formatLastSeen(sensor.lastSeen)}\n\nWhat would you like to do?`,
          [
            { text: 'Cancel', style: 'cancel' },
            {
              text: 'Reconnect',
              onPress: () => router.push(`/(tabs)/beneficiaries/${id}/setup-wifi?deviceId=${sensor.deviceId}&deviceName=${sensor.name}&wellId=${sensor.wellId}` as any)
            },
            {
              text: 'Remove',
              style: 'destructive',
              onPress: () => handleDetachDevice(sensor)
            },
          ]
        );
      }
    }
    // For BLE nearby sensors - go directly to setup
    else if (sensor.source === 'ble') {
      router.push(`/(tabs)/beneficiaries/${id}/setup-wifi?deviceId=${sensor.deviceId}&deviceName=${sensor.name}&wellId=${sensor.wellId}` as any);
    }
    // For online API sensors - navigate to settings
    else {
      handleDeviceSettings(sensor);
    }
  };
 
  const handleDetachDevice = (sensor: WPSensor) => {
    Alert.alert(
      'Detach Sensor',
      `Are you sure you want to detach "${sensor.name}" from ${beneficiaryName}?\n\nThe sensor will become available for use with another person.`,
      [
        { text: 'Cancel', style: 'cancel' },
        {
          text: 'Detach',
          style: 'destructive',
          onPress: async () => {
            setIsDetaching(sensor.deviceId);
            try {
              const response = await api.detachDeviceFromBeneficiary(id!, sensor.deviceId);
 
              if (!response.ok) {
                throw new Error('Failed to detach sensor');
              }
 
              // Remove from local state
              setApiSensors(prev => prev.filter(s => s.deviceId !== sensor.deviceId));
 
              Alert.alert('Success', `${sensor.name} has been detached.`);
            } catch (error) {
              Alert.alert('Error', 'Failed to detach sensor. Please try again.');
            } finally {
              setIsDetaching(null);
            }
          },
        },
      ]
    );
  };
 
  const handleDetachAll = () => {
    if (apiSensors.length === 0) {
      Alert.alert('No Sensors', 'There are no sensors to detach.');
      return;
    }
 
    Alert.alert(
      'Detach All Sensors',
      `Are you sure you want to detach all ${apiSensors.length} sensors from ${beneficiaryName}?\n\nThis action cannot be undone.`,
      [
        { text: 'Cancel', style: 'cancel' },
        {
          text: 'Detach All',
          style: 'destructive',
          onPress: async () => {
            setIsLoading(true);
            try {
              // Detach all sensors sequentially
              for (const sensor of apiSensors) {
                await api.detachDeviceFromBeneficiary(id!, sensor.deviceId);
              }
 
              setApiSensors([]);
              Alert.alert('Success', 'All sensors have been detached.');
            } catch (error) {
              Alert.alert('Error', 'Failed to detach sensors. Please try again.');
            } finally {
              setIsLoading(false);
            }
          },
        },
      ]
    );
  };
 
  const handleAddSensor = () => {
    // Navigate to Add Sensor screen
    router.push(`/(tabs)/beneficiaries/${id}/add-sensor` as any);
  };
 
  const handleDeviceSettings = (sensor: WPSensor) => {
    // Navigate to Device Settings screen
    router.push(`/(tabs)/beneficiaries/${id}/device-settings/${sensor.deviceId}` as any);
  };
 
  const formatLastSeen = (lastSeen: Date): string => {
    const now = new Date();
    const diffMs = now.getTime() - lastSeen.getTime();
    const diffMins = Math.floor(diffMs / 60000);
    const diffHours = Math.floor(diffMs / 3600000);
    const diffDays = Math.floor(diffMs / 86400000);
 
    if (diffMins < 1) return 'Just now';
    if (diffMins < 60) return `${diffMins} min ago`;
    if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
    return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
  };
 
  const getStatusColor = (status: 'online' | 'warning' | 'offline') => {
    switch (status) {
      case 'online':
        return AppColors.success;
      case 'warning':
        return AppColors.warning;
      case 'offline':
        return AppColors.error;
    }
  };
 
  const getStatusLabel = (status: 'online' | 'warning' | 'offline') => {
    switch (status) {
      case 'online':
        return 'Online';
      case 'warning':
        return 'Warning';
      case 'offline':
        return 'Offline';
    }
  };
 
  const getSignalStrength = (rssi: number): string => {
    if (rssi >= -50) return 'Excellent';
    if (rssi >= -60) return 'Good';
    if (rssi >= -70) return 'Fair';
    return 'Weak';
  };
 
  // Convert location ID to display label with icon
  const getLocationDisplay = (locationId: string | undefined): string => {
    if (!locationId) return '';
    const location = ROOM_LOCATIONS.find(l => l.id === locationId);
    if (location) {
      return `${location.icon} ${location.label}`;
    }
    // Fallback for unknown location IDs
    return locationId;
  };
 
  if (isLoading) {
    return (
      <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
        <View style={styles.header}>
          <TouchableOpacity style={styles.backButton} onPress={() => router.back()}>
            <Ionicons name="arrow-back" size={24} color={AppColors.textPrimary} />
          </TouchableOpacity>
          <Text style={styles.headerTitle}>Sensors</Text>
          <View style={styles.placeholder} />
        </View>
        <View style={styles.loadingContainer}>
          <ActivityIndicator size="large" color={AppColors.primary} />
          <Text style={styles.loadingText}>Loading sensors...</Text>
        </View>
      </SafeAreaView>
    );
  }
 
  return (
    <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
      {/* Header */}
      <View style={styles.header}>
        <TouchableOpacity style={styles.backButton} onPress={() => router.back()}>
          <Ionicons name="arrow-back" size={24} color={AppColors.textPrimary} />
        </TouchableOpacity>
        <Text style={styles.headerTitle}>Sensors</Text>
        <BeneficiaryMenu
          beneficiaryId={id || ''}
          userRole={currentBeneficiary?.role}
          currentPage="sensors"
        />
      </View>
 
      {/* Simulator Warning */}
      {!isBLEAvailable && (
        <View style={styles.simulatorWarning}>
          <Ionicons name="information-circle" size={18} color={AppColors.warning} />
          <Text style={styles.simulatorWarningText}>
            Running in Simulator - BLE features use mock data
          </Text>
        </View>
      )}
 
      {/* Error Message */}
      {error && (
        <View style={styles.errorContainer}>
          <View style={styles.errorContent}>
            <Ionicons name="alert-circle" size={24} color={AppColors.error} />
            <Text style={styles.errorText}>{error}</Text>
          </View>
          <TouchableOpacity style={styles.retryButton} onPress={handleRefresh}>
            <Ionicons name="refresh" size={18} color={AppColors.white} />
            <Text style={styles.retryButtonText}>Try Again</Text>
          </TouchableOpacity>
        </View>
      )}
 
      <ScrollView
        style={styles.content}
        contentContainerStyle={styles.scrollContent}
        showsVerticalScrollIndicator={false}
        refreshControl={
          <RefreshControl refreshing={isRefreshing} onRefresh={handleRefresh} />
        }
      >
        {/* Summary Card */}
        <View style={styles.summaryCard}>
          <View style={styles.summaryRow}>
            <View style={styles.summaryItem}>
              <Text style={styles.summaryValue}>{apiSensors.length}</Text>
              <Text style={styles.summaryLabel}>Total</Text>
            </View>
            <View style={styles.summaryDivider} />
            <View style={styles.summaryItem}>
              <Text style={[styles.summaryValue, { color: AppColors.success }]}>
                {apiSensors.filter(s => s.status === 'online').length}
              </Text>
              <Text style={styles.summaryLabel}>Online</Text>
            </View>
            <View style={styles.summaryDivider} />
            <View style={styles.summaryItem}>
              <Text style={[styles.summaryValue, { color: AppColors.warning }]}>
                {apiSensors.filter(s => s.status === 'warning').length}
              </Text>
              <Text style={styles.summaryLabel}>Warning</Text>
            </View>
            <View style={styles.summaryDivider} />
            <View style={styles.summaryItem}>
              <Text style={[styles.summaryValue, { color: AppColors.error }]}>
                {apiSensors.filter(s => s.status === 'offline').length}
              </Text>
              <Text style={styles.summaryLabel}>Offline</Text>
            </View>
          </View>
        </View>
 
        {/* Connected Sensors Section */}
        {apiSensors.length === 0 ? (
          <View style={styles.emptyState}>
            <View style={styles.emptyIconContainer}>
              <Ionicons name="bluetooth-outline" size={48} color={AppColors.textMuted} />
            </View>
            <Text style={styles.emptyTitle}>No Sensors Connected</Text>
            <Text style={styles.emptyText}>
              Add WP sensors to start monitoring {beneficiaryName}'s wellness.
            </Text>
            <TouchableOpacity style={styles.addDeviceButton} onPress={handleAddSensor}>
              <Ionicons name="add" size={20} color={AppColors.white} />
              <Text style={styles.addDeviceButtonText}>Add Sensors</Text>
            </TouchableOpacity>
          </View>
        ) : (
          <>
            <Text style={styles.sectionTitle}>Connected Sensors ({apiSensors.length})</Text>
            <View style={styles.devicesList}>
              {apiSensors.map((sensor) => {
                const isDetachingThis = isDetaching === sensor.deviceId;
                const sensorConfig = {
                  icon: 'water' as const,
                  color: AppColors.primary,
                  bgColor: AppColors.primaryLighter,
                };
 
                return (
                  <TouchableOpacity
                    key={sensor.deviceId}
                    style={styles.deviceCard}
                    onPress={() => handleSensorPress(sensor)}
                    activeOpacity={0.7}
                  >
                    <View style={styles.deviceInfo}>
                      <View style={[styles.deviceIcon, { backgroundColor: sensorConfig.bgColor }]}>
                        <Ionicons name={sensorConfig.icon} size={22} color={sensorConfig.color} />
                      </View>
                      <View style={styles.deviceDetails}>
                        <Text style={styles.deviceName}>{sensor.name}</Text>
                        <View style={styles.deviceMeta}>
                          <View style={[
                            styles.statusDot,
                            { backgroundColor: getStatusColor(sensor.status) }
                          ]} />
                          <Text style={[styles.deviceStatus, { color: getStatusColor(sensor.status) }]}>
                            {getStatusLabel(sensor.status)}
                          </Text>
                          <Text style={styles.deviceMetaSeparator}>•</Text>
                          <Text style={styles.deviceRoom}>{formatLastSeen(sensor.lastSeen)}</Text>
                        </View>
                        <TouchableOpacity
                          onPress={(e) => {
                            e.stopPropagation();
                            handleDeviceSettings(sensor);
                          }}
                          activeOpacity={0.7}
                        >
                          <Text style={[
                            styles.deviceLocation,
                            !sensor.location && styles.deviceLocationPlaceholder
                          ]}>
                            {getLocationDisplay(sensor.location) || 'No location set'}
                          </Text>
                        </TouchableOpacity>
                      </View>
                    </View>
 
                    <View style={styles.deviceActions}>
                      <TouchableOpacity
                        style={styles.settingsButton}
                        onPress={(e) => {
                          e.stopPropagation();
                          handleDeviceSettings(sensor);
                        }}
                      >
                        <Ionicons name="settings-outline" size={20} color={AppColors.primary} />
                      </TouchableOpacity>
                      <TouchableOpacity
                        style={styles.detachButton}
                        onPress={(e) => {
                          e.stopPropagation();
                          handleDetachDevice(sensor);
                        }}
                        disabled={isDetachingThis}
                      >
                        {isDetachingThis ? (
                          <ActivityIndicator size="small" color={AppColors.error} />
                        ) : (
                          <Ionicons name="unlink-outline" size={20} color={AppColors.error} />
                        )}
                      </TouchableOpacity>
                    </View>
                  </TouchableOpacity>
                );
              })}
            </View>
 
            {/* Detach All Button */}
            {apiSensors.length > 1 && (
              <TouchableOpacity style={styles.detachAllButton} onPress={handleDetachAll}>
                <Ionicons name="trash-outline" size={20} color={AppColors.error} />
                <Text style={styles.detachAllText}>Detach All Sensors</Text>
              </TouchableOpacity>
            )}
          </>
        )}
 
        {/* Add Sensors button when sensors already exist */}
        {apiSensors.length > 0 && (
          <TouchableOpacity style={styles.scanButton} onPress={handleAddSensor}>
            <Ionicons name="add" size={20} color={AppColors.white} />
            <Text style={styles.scanButtonText}>Add More Sensors</Text>
          </TouchableOpacity>
        )}
 
        {/* Info Section */}
        <View style={styles.infoCard}>
          <View style={styles.infoHeader}>
            <Ionicons name="information-circle" size={20} color={AppColors.info} />
            <Text style={styles.infoTitle}>About Sensors</Text>
          </View>
          <Text style={styles.infoText}>
            WP sensors monitor wellness metrics via WiFi. Tap a sensor to configure WiFi settings, view detailed status, or troubleshoot connectivity issues.
            {'\n\n'}
            Detaching a sensor removes it from {beneficiaryName}'s monitoring setup. You can then attach it to another person or re-attach it later.
          </Text>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}
 
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: AppColors.background,
  },
  header: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: Spacing.md,
    paddingVertical: Spacing.sm,
    borderBottomWidth: 1,
    borderBottomColor: AppColors.border,
  },
  backButton: {
    padding: Spacing.xs,
  },
  headerTitle: {
    fontSize: FontSizes.lg,
    fontWeight: FontWeights.semibold,
    color: AppColors.textPrimary,
  },
  placeholder: {
    width: 32,
  },
  content: {
    flex: 1,
  },
  scrollContent: {
    padding: Spacing.lg,
    paddingBottom: Spacing.xxl,
  },
  loadingContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    gap: Spacing.md,
  },
  loadingText: {
    fontSize: FontSizes.base,
    color: AppColors.textSecondary,
  },
  // Summary Card
  summaryCard: {
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.xl,
    padding: Spacing.lg,
    marginBottom: Spacing.lg,
    ...Shadows.sm,
  },
  summaryRow: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  summaryItem: {
    flex: 1,
    alignItems: 'center',
  },
  summaryValue: {
    fontSize: FontSizes['2xl'],
    fontWeight: FontWeights.bold,
    color: AppColors.textPrimary,
  },
  summaryLabel: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
    marginTop: 2,
  },
  summaryDivider: {
    width: 1,
    height: 32,
    backgroundColor: AppColors.border,
  },
  // Section Title
  sectionTitle: {
    fontSize: FontSizes.sm,
    fontWeight: FontWeights.semibold,
    color: AppColors.textSecondary,
    marginBottom: Spacing.md,
    textTransform: 'uppercase',
    letterSpacing: 0.5,
  },
  // Devices List
  devicesList: {
    gap: Spacing.md,
  },
  deviceCard: {
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.lg,
    padding: Spacing.md,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    ...Shadows.xs,
  },
  deviceInfo: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.md,
  },
  deviceIcon: {
    width: 48,
    height: 48,
    borderRadius: BorderRadius.lg,
    justifyContent: 'center',
    alignItems: 'center',
  },
  deviceDetails: {
    flex: 1,
  },
  deviceName: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.textPrimary,
  },
  deviceMeta: {
    flexDirection: 'row',
    alignItems: 'center',
    marginTop: 2,
    gap: 4,
  },
  statusDot: {
    width: 6,
    height: 6,
    borderRadius: 3,
  },
  deviceStatus: {
    fontSize: FontSizes.xs,
    color: AppColors.textSecondary,
  },
  deviceMetaSeparator: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
  },
  deviceRoom: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
  },
  deviceActions: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.xs,
  },
  settingsButton: {
    width: 40,
    height: 40,
    borderRadius: BorderRadius.md,
    backgroundColor: AppColors.primaryLighter,
    justifyContent: 'center',
    alignItems: 'center',
  },
  detachButton: {
    width: 40,
    height: 40,
    borderRadius: BorderRadius.md,
    backgroundColor: AppColors.errorLight,
    justifyContent: 'center',
    alignItems: 'center',
  },
  // Empty State
  emptyState: {
    alignItems: 'center',
    padding: Spacing.xl,
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.xl,
    ...Shadows.sm,
  },
  emptyIconContainer: {
    width: 80,
    height: 80,
    borderRadius: 40,
    backgroundColor: AppColors.surfaceSecondary,
    justifyContent: 'center',
    alignItems: 'center',
    marginBottom: Spacing.md,
  },
  emptyTitle: {
    fontSize: FontSizes.lg,
    fontWeight: FontWeights.semibold,
    color: AppColors.textPrimary,
    marginBottom: Spacing.xs,
  },
  emptyText: {
    fontSize: FontSizes.sm,
    color: AppColors.textMuted,
    textAlign: 'center',
    marginBottom: Spacing.lg,
  },
  addDeviceButton: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: AppColors.primary,
    paddingVertical: Spacing.sm,
    paddingHorizontal: Spacing.lg,
    borderRadius: BorderRadius.lg,
    gap: Spacing.xs,
  },
  addDeviceButtonText: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.white,
  },
  // Detach All Button
  detachAllButton: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: AppColors.errorLight,
    paddingVertical: Spacing.md,
    borderRadius: BorderRadius.lg,
    marginTop: Spacing.lg,
    gap: Spacing.sm,
  },
  detachAllText: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.error,
  },
  // Info Card
  infoCard: {
    backgroundColor: AppColors.infoLight,
    borderRadius: BorderRadius.lg,
    padding: Spacing.md,
    marginTop: Spacing.xl,
  },
  infoHeader: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.sm,
    marginBottom: Spacing.xs,
  },
  infoTitle: {
    fontSize: FontSizes.sm,
    fontWeight: FontWeights.semibold,
    color: AppColors.info,
  },
  infoText: {
    fontSize: FontSizes.sm,
    color: AppColors.info,
    lineHeight: 20,
  },
  // WiFi Info
  wifiInfo: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: 4,
    marginTop: 4,
  },
  wifiText: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
  },
  // Simulator Warning
  simulatorWarning: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: AppColors.warningLight,
    paddingVertical: Spacing.xs,
    paddingHorizontal: Spacing.md,
    gap: Spacing.xs,
    borderBottomWidth: 1,
    borderBottomColor: AppColors.warning,
  },
  simulatorWarningText: {
    fontSize: FontSizes.xs,
    color: AppColors.warning,
    fontWeight: FontWeights.medium,
    flex: 1,
  },
  // Scan Button
  scanButton: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: AppColors.primary,
    paddingVertical: Spacing.md,
    borderRadius: BorderRadius.lg,
    marginTop: Spacing.lg,
    marginBottom: Spacing.lg,
    gap: Spacing.sm,
    ...Shadows.md,
  },
  scanButtonText: {
    fontSize: FontSizes.base,
    fontWeight: FontWeights.semibold,
    color: AppColors.white,
  },
  deviceLocation: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
    marginTop: 2,
  },
  deviceLocationPlaceholder: {
    fontStyle: 'italic',
    opacity: 0.6,
  },
  // Error Container
  errorContainer: {
    marginHorizontal: Spacing.lg,
    marginVertical: Spacing.md,
    padding: Spacing.lg,
    backgroundColor: AppColors.errorLight,
    borderRadius: BorderRadius.lg,
    borderWidth: 1,
    borderColor: AppColors.error,
  },
  errorContent: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: Spacing.sm,
    marginBottom: Spacing.md,
  },
  errorText: {
    flex: 1,
    fontSize: FontSizes.base,
    color: AppColors.error,
    fontWeight: FontWeights.medium,
  },
  retryButton: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: AppColors.error,
    paddingVertical: Spacing.sm,
    paddingHorizontal: Spacing.lg,
    borderRadius: BorderRadius.md,
    gap: Spacing.xs,
  },
  retryButtonText: {
    color: AppColors.white,
    fontSize: FontSizes.sm,
    fontWeight: FontWeights.semibold,
  },
});